// my/xiang/xiang.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: '',
    colorval: "",
    localval: "",
    xiaoval: "",
    colors: [{
        name: '银色',
        value: '银色',
        checked: "true"
      },
      {
        name: '金色',
        value: '金色'
      },
      {
        name: '玫瑰金色',
        value: '玫瑰金色'
      },
      {
        name: '红色',
        value: '红色',
      },
      {
        name: '黑色',
        value: '黑色',
      },
    ],
    local: [{
        name: '32G',
        value: '32G',
        // checked: "true"
      },
      {
        name: '128G',
        value: '128G',
      },
      {
        name: '256G',
        value: '256G',
      },
    ],
    xiao: [{
        name: '大陆国行',
        value: '大陆国行',
        // checked: "true"
      },
      {
        name: '香港行货',
        value: '香港行货',
      },
      {
        name: '水货无锁',
        value: '水货无锁',
      },
      {
        name: '水货有锁',
        value: '水货有锁',
      },
      {
        name: '国行官换',
        value: '国行官换',
      },
    ],
    colorshow: true,
    localshow: true,
    xiaoshow: true,
  },
  radioChange: function(e) {

    this.setData({
      colorval: e.detail.value,
      colorshow: false,
    });

    // console.log(this.data.colorval)
  },
  localradiofun(e) {
    // console.log(e)
    this.setData({
      localval: e.detail.value,
      localshow: false,
    });
    // console.log(this.data.localval)
  },
  xiaoradiofun(e) {
    // console.log(e)
    this.setData({
      xiaoval: e.detail.value,
      xiaoshow: false,
    });
    // console.log(this.data.localval)
  },
  colorfun(e) {
    let cs = this.data.colorshow
    let lcs = this.data.localshow
    let xs = this.data.xiaoshow
    let listshow = e.currentTarget.dataset.xq + "show"
    console.log(listshow)
    let that = this
    if (listshow == "colorshow") {
      this.setData({
        colorshow: !cs,
      });
      let yan = this.data.colors.filter(function(item) {
        if (item.name == that.data.colorval) {
          item.checked = true
        } else {
          item.checked = false
        }
        return item
      });
      this.setData({
        colors: yan,
      });
    } else if (listshow == "localshow") {
      this.setData({
        localshow: !lcs,
      });
      let yan = this.data.local.filter((item) => {
        // console.log(this.data.localval)
        // console.log(item.name)
        if (item.name == this.data.localval) {
          item.checked = true
        } else {
          item.checked = false
        }
        return item
      });
      this.setData({
        local: yan,
      });
    } else if (listshow == "xiaoshow") {
      this.setData({
        xiaoshow: !xs,
      });
      console.log(this.data.xiaoshow)
      let yan = this.data.xiao.filter((item) => {
        // console.log(this.data.localval)
        // console.log(item)
        if (item.name == this.data.xiaoval) {
          item.checked = true
        } else {
          item.checked = false
        }
        return item
      });
      this.setData({
        xiao: yan,
      });
    }

    // console.log(yan)

  },
  shoufun(e) {
    console.log(this)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (options.key) {

      this.setData({
        phone: options.key
      });
    } else {
      this.setData({
        phone: options.name
      });
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    // let that = this;
    // wx.getSystemInfo({
    //   success(res) {
    //     that.setData({
    //       phone: res.model
    //     });
    //     // console.log(res.pixelRatio)
    //     // console.log(res.windowWidth)
    //     // console.log(res.windowHeight)
    //     // console.log(res.language)
    //     // console.log(res.version)
    //     // console.log(res.platform)
    //   }
    // })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})